#!/bin/sh
# - nr_task
# - runtime
# - build_kconfig
# - target

. $LKP_SRC/lib/debug.sh
. $LKP_SRC/lib/reproduce-log.sh

## Build linux kernel

: ${runtime:=300}
: ${build_kconfig:=defconfig}

[ -n "$target" ] || target=vmlinux

run_kbuild()
{
	start_time=$(date +%s)
	iterations=0
	while true; do
		log_cmd make mrproper || die "make mrproper failed"
		log_cmd make $build_kconfig || die "make $build_kconfig failed"
		log_cmd make -j $nr_task $target 2> /dev/null || die "make -j $nr_task $target failed"
		iterations=$((iterations + 1))
		now=$(date +%s)
		[ $((now - start_time)) -gt "$runtime" ] && break
	done
	echo "iterations: $iterations"
	echo "runtime: $((now - start_time))"
}

cd $BENCHMARK_ROOT/kbuild/linux || die "no kernel source code in $BENCHMARK_ROOT/kbuild/linux"

run_kbuild
